package com.haiya.factory.absfactory.basic;

import com.haiya.factory.absfactory.basic.factory.AbstractFactory;
import com.haiya.factory.absfactory.basic.factory.ConcreteFactory1;
import com.haiya.factory.absfactory.basic.factory.ConcreteFactory2;
import com.haiya.factory.absfactory.basic.product.Product1;
import com.haiya.factory.absfactory.basic.product.Product2;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Client {
    public static void main(String[] args) throws IOException {
        BufferedReader strin = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("input factory name: ");
        String factoryName = strin.readLine();
        System.out.println("input product name: ");
        String productName = strin.readLine();

        AbstractFactory factory = null;

        if (factoryName.equals("factory1")) {
            factory = new ConcreteFactory1();

            if (productName.equals("product1")) {
                Product1 product = factory.newProduct1();
                product.show();
            } else if (productName.equals("product2")) {
                Product2 product = factory.newProduct2();
                product.show();
            }
        } else if (factoryName.equals("factory2")) {
            factory = new ConcreteFactory2();

            if (productName.equals("product1")) {
                Product1 product = factory.newProduct1();
                product.show();
            } else if (productName.equals("product2")) {
                Product2 product = factory.newProduct2();
                product.show();
            }
        }
    }
}
